package com.getpebble.android.framework.endpoint;

import android.graphics.Bitmap;
import com.getpebble.android.bluetooth.protocol.ProtocolMessage;
import com.getpebble.android.common.core.trace.Trace;
import com.getpebble.android.common.model.FrameworkState;
import com.getpebble.android.framework.endpoint.EndpointRequest.EndpointAction;
import com.getpebble.android.framework.endpoint.EndpointRequest.EndpointArgumentKeys;
import com.getpebble.android.framework.protocol.EndpointId;
import com.getpebble.android.framework.protocol.outbound.PblOutboundAppCustomizeMessage;
import com.getpebble.android.framework.protocol.outbound.PblOutboundAppCustomizeMessage.AppType;
import com.google.common.collect.ImmutableSet;
import com.sun.mail.smtp.SMTPMessage;
import java.util.Set;

public class CustomizeAppEndpoint extends RequestableEndpoint {
    private static final String TAG = CustomizeAppEndpoint.class.getSimpleName();
    private IEndpointMessageSender mMessageSender;

    static /* synthetic */ class AnonymousClass1 {
        static final /* synthetic */ int[] $SwitchMap$com$getpebble$android$framework$endpoint$EndpointRequest$EndpointAction = new int[EndpointAction.values().length];

        static {
            try {
                $SwitchMap$com$getpebble$android$framework$endpoint$EndpointRequest$EndpointAction[EndpointAction.CUSTOMIZE_APP.ordinal()] = 1;
            } catch (NoSuchFieldError e) {
            }
        }
    }

    public CustomizeAppEndpoint(IEndpointMessageSender messageSender) {
        this.mMessageSender = messageSender;
    }

    boolean onRequest(EndpointRequest request, FrameworkState frameworkState) {
        boolean handled = false;
        Trace.debug(TAG, "Got request: " + request.getAction());
        switch (AnonymousClass1.$SwitchMap$com$getpebble$android$framework$endpoint$EndpointRequest$EndpointAction[request.getAction().ordinal()]) {
            case SMTPMessage.RETURN_FULL /*1*/:
                Trace.debug(TAG, "Sending customize app messages");
                int appTypeInt = request.getInt(EndpointArgumentKeys.APP_TYPE).intValue();
                AppType appType = AppType.fromByte((byte) appTypeInt);
                if (!AppType.UNKNOWN.equals(appType)) {
                    String title = request.getString(EndpointArgumentKeys.APP_TITLE);
                    Bitmap icon = (Bitmap) request.getParcelable(EndpointArgumentKeys.BITMAP);
                    if (title != null) {
                        this.mMessageSender.sendMessage(PblOutboundAppCustomizeMessage.createCustomizeTitleMessage(appType, title));
                    }
                    if (icon != null) {
                        this.mMessageSender.sendMessage(PblOutboundAppCustomizeMessage.createCustomizeIconMessage(appType, icon));
                    }
                    handled = true;
                    break;
                }
                Trace.warning(TAG, "CUSTOMIZE_APP message received with invalid AppType (" + appTypeInt + ")");
                return true;
            default:
                Trace.debug(TAG, "No matching request found in CustomizeAppEndpoint, not handling.");
                break;
        }
        return handled;
    }

    boolean onPrfRequest(EndpointRequest request, FrameworkState frameworkState) {
        return true;
    }

    Set<EndpointId> getSupportedEndpoints() {
        return ImmutableSet.of(EndpointId.APP_CUSTOMIZE);
    }

    boolean onReceive(ProtocolMessage message) {
        return true;
    }
}
